package co.yixiang.modules.supplier.repository;

import co.yixiang.modules.supplier.domain.SupplierGoodsSkuLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
* @author Walert
* @date 2021-03-27
*/
public interface SupplierGoodsSkuLogRepository extends JpaRepository<SupplierGoodsSkuLog, Long>, JpaSpecificationExecutor<SupplierGoodsSkuLog> {

    @Query(value = "select  " +
                "   change_time as changeTime,  " +
                "   max(first_source_price)        as firstSourcePrice, " +
                "   max(first_sale_price)          as firstSalePrice,  " +
                "   max(second_source_price)       as secondSourcePrice, " +
                "   max(second_sale_price)         as secondSalePrice,  " +
                "   max(thrid_source_price)        as thridSourcePrice, " +
                "   max(thrid_sale_price)          as thridSalePrice,  " +
                "   max(source_price)              as sourcePrice, " +
                "   max(sale_price)                as salePrice " +
                "   from supplier_goods_sku_log where sku_id = ?1 group by change_time order by change_time asc",nativeQuery = true)
    List<Map<String,Long>> getPricesBySkuId(Long skuId);


    List<SupplierGoodsSkuLog> findByChangeTimeAndSkuId(long changeTime,long skuId);
}
